#include <tsin/library/BulletEvent.hpp>

#include <tsin/runtime/BulletRuntime.hpp>

using namespace tsin;

BulletEvent::BulletEvent(bool d)
        : DynamicObject(d), list(0), idx(0)
{
}

DynamicEvent BulletEvent::postTick(void *data, void *priv_data)
{
        DynamicEvent ret = EVENT_NONE;
        if (priv_data == 0) {
                /* Update the event arguments themselves */
                DynamicObject::postTick(data);
        } else {
                BulletRuntime *bullet = static_cast<BulletRuntime *>(priv_data);
                if (trigger(*bullet, data))
                        if (handle(*bullet, data) != this)
                                ret |= EVENT_END;
        }
        return ret;
}

void BulletEvent::setNext(BulletEvent **list, int idx)
{
        this->list = list;
        this->idx = idx;
}

BulletEvent *BulletEvent::next()
{
        return list ? list[idx] : 0;
}

char BulletEvent::getDescriptor()
{
        return 'P';
}
